package com.dci.controller.project;

import com.alibaba.fastjson.JSONObject;
import com.dci.context.Config;
import com.dci.model.project.*;
import com.dci.param.SearchMap;
import com.dci.result.JsonData;
import com.dci.result.PageResult;
import com.dci.result.ResultInfo;
import com.dci.result.ResultUtil;
import com.dci.service.project.OutboundInfoService;
import com.dci.service.project.PlanFeedbackInfoService;
import com.dci.service.project.PlanInfoService;
import com.dci.service.project.ProjectInfoService;
import com.dci.util.UUIDBuild;
import com.google.gson.Gson;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;


/**
 * All rights Reserved, Designed By 姑苏区政府大数据中心
 *
 * @version V1.0
 * @Title: null.java
 * @Package com.dci.controller.project
 * @Description: 储备库管理
 * @author: 张星亮
 * @date: 2019/2/25
 * @Copyright: 2019 姑苏区政府大数据中心. All rights reserved.
 * 注意：本内容仅限于姑苏区政府大数据中心内部传阅，禁止外泄以及用于其他的商业目
 */
@Controller
@RequestMapping("/managerProtect")
public class ProjectManagerController {

    @Resource
    private ProjectInfoService projectInfoService;

    @Resource
    private PlanInfoService planInfoService;

    @Resource
    private PlanFeedbackInfoService feedbackInfoService;

    @Resource
    private OutboundInfoService outboundInfoService;

    @Value("${upload.path}")
    private String path;
    @Value("${upload.url}")
    private String url;
    @Value("${upload.urlP}")
    private String urlP;


    /**
     * 新增 项目申报 (暂时作废)
     *
     * @param projectInfo
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public JsonData saveProjectInfo(@RequestBody ProjectInfo projectInfo) {
        try {
            JsonData result = projectInfoService.saveProjectInfo(projectInfo);
            return result;
        } catch (Exception e) {
            return JsonData.success(null, 911);
        }
    }


    /**
     * 提交表单和上传文件
     *
     * @param
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @PostMapping("/uploadAndSave")
    @ResponseBody
    public JsonData uploadAndSave(@RequestParam("uploadFile") MultipartFile[] files, @RequestParam("form") String form) {
        Date now = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        String address = df.format(now);
        String filePath = path + File.separator + address + "/";
        String fileNames = "";
        if (files.length != 0) {
            for (MultipartFile file : files) {
                String fileName = file.getOriginalFilename();
                if (fileNames == "") {
                    fileNames += fileName;
                } else {
                    fileNames += ',' + fileName;
                }
                File fileDir = new File(filePath);
                if (!fileDir.exists()) {
                    fileDir.mkdirs();
                }
                try {
                    file.transferTo(new File(fileDir.getAbsolutePath(), fileName));
                } catch (IOException e) {
                    continue;
                }
            }
        }
        // 数据库存储的相对路径
        // String urlPath = url + "/" + address + "/";
        String urlPath = urlP + address + "/";
        return projectInfoService.uploadAndSave(form, urlPath, fileNames);
    }


    /**
     * 提交表单和上传文件
     *
     * @param
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @PostMapping("/approvalAndSave")
    @ResponseBody
    public JsonData approvalAndSave(@RequestParam("assessFile") MultipartFile[] assessFile, @RequestParam("designFile") MultipartFile[] designFile,
                                    @RequestParam("constructFile") MultipartFile[] constructFile, @RequestParam("completedFile") MultipartFile[] completedFile,
                                    @RequestParam("locationFile") MultipartFile[] locationFile, @RequestParam("formData") String formData) {
        Date now = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyymmddHHMMss");
        String address = df.format(now);
        String filePath = path + File.separator + address + "/";
        String fileNames = "";
        String videoFileNames = "";
        String constructionFileNames = "";
        String completionFileNames = "";
        String locationFileNames = "";
        File fileDir = new File(filePath);
        if (!fileDir.exists()) {
            fileDir.mkdirs();
        }
        if (assessFile.length != 0) {
            for (MultipartFile file : assessFile) {
                String fileName = file.getOriginalFilename();
                if (fileNames == "") {
                    fileNames += fileName;
                } else {
                    fileNames += ',' + fileName;
                }
                try {
                    file.transferTo(new File(fileDir.getAbsolutePath(), fileName));
                } catch (IOException e) {
                    continue;
                }
            }
        }

        if (designFile.length != 0) {
            for (MultipartFile file : designFile) {
                String fileName = file.getOriginalFilename();
                if (videoFileNames == "") {
                    videoFileNames += fileName;
                } else {
                    videoFileNames += ',' + fileName;
                }
                try {
                    file.transferTo(new File(fileDir.getAbsolutePath(), fileName));
                } catch (IOException e) {
                    continue;
                }
            }
        }

        if (constructFile.length != 0) {
            for (MultipartFile file : constructFile) {
                String fileName = file.getOriginalFilename();
                if (constructionFileNames == "") {
                    constructionFileNames += fileName;
                } else {
                    constructionFileNames += ',' + fileName;
                }
                try {
                    file.transferTo(new File(fileDir.getAbsolutePath(), fileName));
                } catch (IOException e) {
                    continue;
                }
            }
        }

        if (completedFile.length != 0) {
            for (MultipartFile file : completedFile) {
                String fileName = file.getOriginalFilename();
                if (completionFileNames == "") {
                    completionFileNames += fileName;
                } else {
                    completionFileNames += ',' + fileName;
                }
                try {
                    file.transferTo(new File(fileDir.getAbsolutePath(), fileName));
                } catch (IOException e) {
                    continue;
                }
            }
        }

        if (locationFile.length != 0) {
            for (MultipartFile file : locationFile) {
                String fileName = file.getOriginalFilename();
                if (locationFileNames == "") {
                    locationFileNames += fileName;
                } else {
                    locationFileNames += ',' + fileName;
                }
                try {
                    file.transferTo(new File(fileDir.getAbsolutePath(), fileName));
                } catch (IOException e) {
                    continue;
                }
            }
        }

        /* 数据库存储的相对路径 */
        String urlPath = url + "/" + address + "/";
        String id = UUIDBuild.getUUID();
        JSONObject jsonObject = JSONObject.parseObject(formData);
        ProjectManager projectManager = JSONObject.toJavaObject(jsonObject, ProjectManager.class);
        projectManager.setId(id);
        if (projectManager.getQuarterlyProgress() == null) {
            projectManager.setQuarterlyProgress("");
        }
        Calendar c = Calendar.getInstance();
        String year = String.valueOf(c.get(Calendar.YEAR));
        String quart = "";
        int currentMonth = c.get(Calendar.MONTH) + 1;
        if (currentMonth >= 1 && currentMonth <= 3)
            quart = "第一季度";
        else if (currentMonth >= 4 && currentMonth <= 6)
            quart = "第二季度";
        else if (currentMonth >= 7 && currentMonth <= 9)
            quart = "第三季度";
        else if (currentMonth >= 10 && currentMonth <= 12)
            quart = "第四季度";
        projectManager.setQuarterlyProgress(projectManager.getQuarterlyProgress() + "**" + year + "年" + quart + "**");
        if (projectManager.getQuarterPlan() == null) {
            projectManager.setQuarterPlan("");
        }
        projectManager.setQuarterPlan(projectManager.getQuarterPlan() + "**" + year + "年" + quart + "**");
        projectManager.setFileAddress(urlPath);
        projectManager.setFileNamesQuo(fileNames);
        projectManager.setFileNamesConcept(videoFileNames);
        projectManager.setFileNamesConstruction(constructionFileNames);
        projectManager.setFileNamesCompletion(completionFileNames);
        projectManager.setFileNamesLocation(locationFileNames);
        projectManager.setCreateTime(new Date());
        // projectManager.setStatus("项目确立");
        projectManager.setProjectFlow("项目确立");
        projectManager.setOperate("add");
        //0:未审核 1:审核通过 2:审核不通过
        projectManager.setAuditStatus("0");
        //获取申报人
        // projectManager.setCreateUser("name");
        return projectInfoService.saveProtect(projectManager);
    }

    /***
     * 条件查询某一类型保护对象信息
     * @param searchMap 查询条件
     * @param pageNum 页数
     * @param pageSize 每页总数
     * @return pageResult 封装的返回参数
     */
    @PostMapping("/findList/{pageNum}/{pageSize}")
    @ResponseBody
    @ApiOperation("条件查询某一类型保护对象信息")
    public PageResult findList(@RequestBody(required = false) SearchMap searchMap, @PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize) {
        if (!StringUtils.isEmpty(searchMap.getName())) {
            searchMap.setName(searchMap.getName().replaceAll("%", "\\\\%")
                    .replaceAll("_", "\\\\_"));
        }
        PageResult pageResult = projectInfoService.findList(searchMap, pageNum, pageSize);
        return pageResult;
    }

    /**
     * 根据主键查询详细
     *
     * @param projectInfo
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/getProject")
    @ResponseBody
    public JsonData selectProjectByPrimaryKey(@RequestBody ProjectInfo projectInfo) {
        try {
            JsonData result = projectInfoService.selectProjectByPrimaryKey(projectInfo);
            return result;
        } catch (Exception e) {
            return JsonData.success(null, 911);
        }
    }


    /**
     * 根据条件查询项目列表,分页
     *
     * @param projectInfo
     * @return PageResult 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/getProjectPages")
    @ResponseBody
    public PageResult selectProjectPages(@RequestBody ProjectInfo projectInfo) {
//        List<UrlName> list = new ArrayList<>();
//        UrlName urlName = new UrlName();
//        String filePath = projectInfo.getFilePath();
//        File f = new File(filePath);
//        File[] files = f.listFiles();
//        for (File file : files) {
//            String fileName1 = file.getName();
//            urlName.setName(fileName1);
//            String url = filePath + fileName1;
//            urlName.setUrl(url);
//            list.add(urlName);
//        }
        try {
            PageResult result = projectInfoService.selectProjectPages(projectInfo);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return PageResult.fail(911);
        }
    }


    /**
     * 项目信息修改
     *
     * @param projectInfo
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public ResultInfo updateProjectByPrimaryKeySelective(@RequestBody ProjectInfo projectInfo) {
        try {
            ResultInfo result = projectInfoService.updateProjectByPrimaryKeySelective(projectInfo);
            return result;
        } catch (Exception e) {
            return ResultUtil.createFail(Config.MESSAGE, 911, null);
        }
    }


    /**
     * 入库管理删除 (逻辑删除)
     *
     * @param list
     * @return PageResult 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public PageResult deleteProject(@RequestBody List<ProjectInfo> list) {
        try {
            PageResult result = projectInfoService.deleteProject(list);
            return result;
        } catch (Exception e) {
            return PageResult.fail(911);
        }
    }


    /**
     * 入库管理,项目审核方法
     *
     * @param projectInfo
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/audit")
    @ResponseBody
    public JsonData audit(@RequestBody ProjectInfo projectInfo) {
        try {
            projectInfo = projectInfoService.audit(projectInfo);
            return JsonData.success(projectInfo, 906);
        } catch (Exception e) {
            return JsonData.success(null, 911);
        }
    }

    /**
     * 入库管理,项目审核方法
     *
     * @param projectInfo
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/auditFail")
    @ResponseBody
    public JsonData auditFail(@RequestBody ProjectInfo projectInfo) {
        try {
            projectInfo = projectInfoService.auditFail(projectInfo);
            return JsonData.success(projectInfo, 906);
        } catch (Exception e) {
            return JsonData.success(null, 911);
        }
    }


    /**
     * 入库管理,项目审批方法
     *
     * @param projectInfo
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/approval")
    @ResponseBody
    public JsonData approval(@RequestBody ProjectInfo projectInfo) {
        try {
            projectInfo = projectInfoService.approval(projectInfo);
            return JsonData.success(projectInfo, 906);
        } catch (Exception e) {
            return JsonData.success(null, 911);
        }
    }

    /**
     * 入库管理,项目审批方法
     *
     * @param projectInfo
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/approvalFail")
    @ResponseBody
    public JsonData approvalFail(@RequestBody ProjectInfo projectInfo) {
        try {
            projectInfo = projectInfoService.approvalFail(projectInfo);
            return JsonData.success(projectInfo, 906);
        } catch (Exception e) {
            return JsonData.success(null, 911);
        }
    }

    /**
     * 入库管理,审批,项目分类修改方法
     *
     * @param projectInfo
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/updateProjectType")
    @ResponseBody
    public JsonData updateProjectType(@RequestBody ProjectInfo projectInfo) {
        try {
            projectInfo = projectInfoService.updateProjectType(projectInfo);
            return JsonData.success(projectInfo, 906);
        } catch (Exception e) {
            return JsonData.success(null, 911);
        }
    }


    /**
     * 新增储备前期工作进度计划表
     *
     * @param planInfo
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/savePlanInfo")
    @ResponseBody
    public ResultInfo insertSelective(@RequestBody PlanInfo planInfo) {
        try {
            planInfoService.insertSelective(planInfo);
            return ResultUtil.createSuccess(Config.MESSAGE, 906, null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.createFail(Config.MESSAGE, 911, null);
        }
    }

    /**
     * 新增储备前期工作进度计划表（计划转实施）
     *
     * @param planInfo
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/addPlanInfo")
    @ResponseBody
    public ResultInfo addSelective(@RequestBody PlanInfo planInfo) {
        try {
            planInfoService.addSelective(planInfo);
            return ResultUtil.createSuccess(Config.MESSAGE, 906, null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.createFail(Config.MESSAGE, 911, null);
        }
    }


    /**
     * 根据 ProjectId 获取相关进度信息列表
     *
     * @param projectInfo
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/getPlanInfoList")
    @ResponseBody
    public JsonData selectByProjectId(@RequestBody ProjectInfo projectInfo) {
        try {
            JsonData result = planInfoService.selectByProjectId(projectInfo);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return JsonData.success(null, 911);
        }
    }


    /**
     * 批量更新项目进度计划表信息
     *
     * @param list
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/updatePlan")
    @ResponseBody
    public JsonData batchUpdatePlanInfo(@RequestBody List<PlanInfo> list) {

        try {
            return planInfoService.batchUpdatePlanInfo(list);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonData.success(null, 911);
        }

    }

    /**
     * 查询在库管理页面列表
     *
     * @param projectInfo
     * @return PageResult 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/getInStoreList")
    @ResponseBody
    public PageResult selectInStoreProjectList(@RequestBody ProjectInfo projectInfo) {
        try {
            return projectInfoService.selectInStoreProjectList(projectInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return PageResult.fail(911);
        }
    }


    /**
     * 查询出库管理页面列表
     *
     * @param projectInfo
     * @return PageResult 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/getOutBoundList")
    @ResponseBody
    public PageResult getOutBoundList(@RequestBody ProjectInfo projectInfo) {
        try {
            return projectInfoService.getOutBoundList(projectInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return PageResult.fail(911);
        }
    }


    /**
     * 检查 项目进度计划是否已经存在反馈信息
     *
     * @param feedbackInfo
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/checkStatus")
    @ResponseBody
    public JsonData checkFeedbackStatus(@RequestBody PlanFeedbackInfo feedbackInfo) {
        try {
            JsonData result = feedbackInfoService.checkFeedbackStatus(feedbackInfo);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return JsonData.success(null, 911);
        }
    }


    /**
     * 保存提交的反馈信息
     *
     * @param feedback
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/saveFeedbackInfo")
    @ResponseBody
    public JsonData saveFeedbackInfo(@RequestParam("uploadFile") MultipartFile[] files, @RequestParam("feedback") String feedback) {
        Gson gson = new Gson();
        PlanFeedbackInfo feedbackInfo = gson.fromJson(feedback, PlanFeedbackInfo.class);
        Date now = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        String address = df.format(now);
        String filePath = path + File.separator + address + "/";
        String fileNames = "";
        if (files.length != 0) {
            for (MultipartFile file : files) {
                String fileName = file.getOriginalFilename();
                if (fileNames == "") {
                    fileNames += fileName;
                } else {
                    fileNames += ',' + fileName;
                }
                File fileDir = new File(filePath);
                if (!fileDir.exists()) {
                    fileDir.mkdirs();
                }
                try {
                    file.transferTo(new File(fileDir.getAbsolutePath(), fileName));
                } catch (IOException e) {
                    continue;
                }
            }
        }
        String urlPath = urlP + address + "/";
        feedbackInfo.setFeedback_url(urlPath);
        feedbackInfo.setFeedback_file(fileNames);
        try {
            JsonData result = feedbackInfoService.insert(feedbackInfo);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return JsonData.success(null, 911);
        }
    }


    /**
     * 反馈信息审核
     *
     * @param feedbackInfo
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping("/auditFeedback")
    @ResponseBody
    public JsonData auditFeedback(@RequestBody PlanFeedbackInfo feedbackInfo) {

        try {
            JsonData result = feedbackInfoService.auditFeedback(feedbackInfo);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return JsonData.success(null, 911);
        }
    }


    /**
     * 保存出库申请信息
     *
     * @param files
     * @param outform
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/saveApply")
    @ResponseBody
    public JsonData saveOutBoundApply(@RequestParam("outFile") MultipartFile[] files, @RequestParam("form") String outform) {
        Gson gson = new Gson();
        OutboundInfo outboundInfo = gson.fromJson(outform, OutboundInfo.class);
        String projectId = outboundInfo.getProjectId();
        List<ProjectInfo> list = projectInfoService.selectByOutId(projectId);
        String url = list.get(0).getFilePath();
        String result = "";
        String fileNames = "";
        int i = 0;
        while (i < 2) {
            int lastFirst = url.lastIndexOf('/');
            result = url.substring(lastFirst) + result;
            url = url.substring(0, lastFirst);
            i++;
        }
        String P = result.substring(1);
        String filePath = path + "/" + P;
        if (files.length != 0) {
            for (MultipartFile file : files) {
                String fileName = file.getOriginalFilename();
                if (fileNames == "") {
                    fileNames += fileName;
                } else {
                    fileNames += ',' + fileName;
                }
                File fileDir = new File(filePath);
                if (!fileDir.exists()) {
                    fileDir.mkdirs();
                }
                try {
                    file.transferTo(new File(fileDir.getAbsolutePath(), fileName));
                } catch (IOException e) {
                    continue;
                }
            }
        }
        try {
            return outboundInfoService.insert(outboundInfo, fileNames);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonData.success(null, 911);
        }
    }


    /**
     * 获取出库申请信息
     *
     * @param outboundInfo
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/getOtuBoundInfo")
    @ResponseBody
    public JsonData getOtuBoundInfo(@RequestBody OutboundInfo outboundInfo) {

        try {
            return outboundInfoService.getOtuBoundInfo(outboundInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonData.success(null, 911);
        }
    }


    /**
     * 判断是否已经申请出库
     *
     * @param record
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping("/checkOutBoundStatus")
    @ResponseBody
    public JsonData checkOutBoundStatus(@RequestBody OutboundInfo record) {
        String projectId = record.getProjectId();
        List<ProjectInfo> list = projectInfoService.selectByOutId(projectId);
        JsonData re = outboundInfoService.selectByProjectId(record, list);
        try {
            return outboundInfoService.selectByProjectId(record, list);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonData.success(null, 911);
        }
    }


    /**
     * 出库审核
     *
     * @param record
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping("/updateAuditInfo")
    @ResponseBody
    public JsonData updateAuditInfo(@RequestBody OutboundInfo record) {
        try {
            return outboundInfoService.updateAuditInfo(record);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonData.success(null, 911);
        }
    }


    /**
     * 出库管理 > 移交
     *
     * @param record
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping("/auditMove")
    @ResponseBody
    public JsonData auditMove(@RequestBody OutboundInfo record) {
        try {
            return outboundInfoService.auditMove(record);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonData.success(null, 911);
        }
    }

    /**
     * 驳回时修改出库状态
     *
     * @param id
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping("/updateOutStatus")
    @ResponseBody
    public ResultInfo updateOutStatus(@RequestParam("id") String id) {
        ProjectInfo record = new ProjectInfo();
        record.setId(id);
        return projectInfoService.updateOutStatus(record);
    }

    /**
     * 通过id修改
     *
     * @param projectInfo
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @PutMapping("/updateTypeById")
    @ResponseBody
    public ResultInfo updateTypeById(@RequestBody ProjectInfo projectInfo) {
        return projectInfoService.updateTypeById(projectInfo);
    }


    /**
     * 根据条件查询项目列表,分页
     *
     * @param projectManager
     * @return PageResult 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/getProjectPagesList")
    @ResponseBody
    public PageResult selectProjectPagesList(@RequestBody ProjectManager projectManager) {
        try {
            PageResult result = projectInfoService.selectProjectPagesList(projectManager);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return PageResult.fail(911);
        }
    }

    /**
     * 项目审核方法--通过
     *
     * @param projectManager
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @PostMapping("/auditList")
    @ResponseBody
    public JsonData auditList(@RequestBody ProjectManager projectManager) {
        try {
            projectManager = projectInfoService.auditList(projectManager);
            return JsonData.success(projectManager, 906);
        } catch (Exception e) {
            return JsonData.success(null, 911);
        }
    }

    /**
     * 入库管理,项目审核方法--驳回
     *
     * @param projectManager
     * @return JsonData 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/auditFailList")
    @ResponseBody
    public JsonData auditFailList(@RequestBody ProjectManager projectManager) {
        try {
            projectManager = projectInfoService.auditFailList(projectManager);
            return JsonData.success(projectManager, 906);
        } catch (Exception e) {
            return JsonData.success(null, 911);
        }
    }

    /**
     * 项目信息修改
     *
     * @param projectManager
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @RequestMapping(value = "/updateList")
    @ResponseBody
    public ResultInfo updateProject(@RequestBody ProjectManager projectManager) {
        try {
            ResultInfo result = projectInfoService.updateProject(projectManager);
            return result;
        } catch (Exception e) {
            return ResultUtil.createFail(Config.MESSAGE, 911, null);
        }
    }

    /**
     * 未审核查询
     *
     * @param projectManager
     * @return PageResult 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @PostMapping("/getUnreviewedList")
    @ResponseBody
    @ApiOperation("未审核查询")
    public PageResult getUnreviewedList(@RequestBody ProjectManager projectManager) {
        try {
            if (!StringUtils.isEmpty(projectManager.getName())) {
                projectManager.setName(projectManager.getName().replaceAll("%", "\\\\%")
                        .replaceAll("_", "\\\\_"));
            }
            if (!StringUtils.isEmpty(projectManager.getProjectFlow())) {
                projectManager.setProjectFlow(projectManager.getProjectFlow().replaceAll("%", "\\\\%")
                        .replaceAll("_", "\\\\_"));
            }
            PageResult result = projectInfoService.getUnreviewedList(projectManager);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return PageResult.fail(911);
        }
    }


    /**
     * 根据主键批量删除记录信息接口
     *
     * @param object id信息
     * @return ResultInfo 封装数据 成功msg:906 失败msg:911
     */
    @DeleteMapping("/deleteById")
    @ResponseBody
    @ApiOperation("删除记录信息接口")
    public ResultInfo deleteByPrimaryKey(@RequestBody String object) {
        return projectInfoService.deleteById(object);
    }



}
